package com.key.service.impl;

import com.key.common.TranException;
import com.key.common.vo.AssetHistoryVO;
import com.key.common.vo.AssetListVO1;
import com.key.common.vo.DetailedTreatmentVO;
import com.key.mapper.AssetHistoryMapper;
import com.key.service.AssetHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author：朕
 * @Package：com.key.service.impl
 * @Project：ams_system
 * @name：findAssetHistoryServiceImpl
 * @Date：2023/2/23 22:09
 * @Filename：findAssetHistoryServiceImpl
 */
@Service
public class AssetHistoryServiceImpl implements AssetHistoryService {

    @Autowired
    private AssetHistoryMapper assetHistoryMapper;


    /**
     * 显示资产履历
     * @return
     */
    @Override
    public List<AssetHistoryVO> findAssetHistory1() {

        List<AssetHistoryVO> assetHistoryVOS = assetHistoryMapper.findAssetHistory();
        return assetHistoryVOS;
    }


    /**
     * 显示资产处理详情
     * @return
     */
    @Override
    public List<DetailedTreatmentVO>  findAssetHistory2(Integer Id) {
        DetailedTreatmentVO p = assetHistoryMapper.physicalChange(Id);//实物变更
        p.setDocumentType("实物信息变更");
        System.out.println(p);
        DetailedTreatmentVO m1 = assetHistoryMapper.maintenanceInformationRegistration1(Id); //维保信息登记
        m1.setDocumentType("维保信息登记");
        DetailedTreatmentVO c = assetHistoryMapper.ChangesFinancialInformation(Id); //财务变更
        c.setDocumentType("财务变更");
        DetailedTreatmentVO m2 = assetHistoryMapper.maintenanceInformationRegistration2(Id);//维修信息登记
        m2.setDocumentType("维修信息登记");
        List list = new ArrayList();
        list.add(p);
        list.add(m1);
        list.add(c);
        list.add(m2);
        return list;
    }

    /**
     * 根据资产处理详情日期显示资产清单
     * @return
     */
    @Override
    public List<List> findAssetHistoryDT(String Date,Integer assets_id) {
        Map<String,Object> map = new HashMap<>();
        String[] date = Date.split(",");
        String Date1 = date[0];
        String Date2 = date[1];
        map.put("Date1",Date1);
        map.put("Date2",Date2);
        map.put("assets_id",assets_id);

        DetailedTreatmentVO a = assetHistoryMapper.findAssetHistoryByDate1(map);
        a.setDocumentType("实物信息变更");


        DetailedTreatmentVO b = assetHistoryMapper.findAssetHistoryByDate2(map);
        b.setDocumentType("维保信息登记");


        DetailedTreatmentVO c = assetHistoryMapper.findAssetHistoryByDate3(map);
        c.setDocumentType("财务信息变更");


        DetailedTreatmentVO d = assetHistoryMapper.findAssetHistoryByDate4(map);
        d.setDocumentType("维修信息登记");

        List list = new ArrayList();
        list.add(a);
        list.add(b);
        list.add(c);
        list.add(d);

        if(list.size()>0){
            AssetHistoryVO assetHistoryVOS = assetHistoryMapper.findAssetHistoryById(assets_id);
            list.add(assetHistoryVOS);
            return list;
        }
        return null;
    }

    /**
     * 高级查询
     * @param string
     * @return
     */
    @Override
    public List<AssetHistoryVO> findAssetHistoryByAnd(String string) {
        List<AssetHistoryVO>  assetHistoryVOS = assetHistoryMapper.findAssetListByCode(string);
        List<AssetHistoryVO>  assetHistoryVOS1 = assetHistoryMapper.findAssetListByType(string);
        if(assetHistoryVOS.size()>0){
            return assetHistoryVOS;
        }else if(assetHistoryVOS1.size()>0){
            return assetHistoryVOS1;
        }else {
           return assetHistoryVOS;
        }

    }
}
